<template>
  <div v-if="exhibitionList.length>0">
    <div v-if="exhibitionList.length==1"
         style="padding:10px 10px 10px 0;margin-bottom: 20px;">当前展会：{{exhibitionList[0].title}}</div>
    <div v-if="exhibitionList.length>1"
         class="handle-box">
      <span style="padding:10px 10px 10px 0;">当前展会：</span>
      <el-select v-model="exhibitionId"
                 placeholder="选择展会"
                 @change="exhibitionSelect"
                 style="width: auto;display: inline-block;">
        <el-option v-for="item in exhibitionList"
                   :key="item.id"
                   :label="item.title"
                   :value="item.id">
        </el-option>
      </el-select>
      <span style="padding:7px;"></span>
      <el-checkbox v-model="checked1" label="锁定展会" @change="changeExhibition" border></el-checkbox>
    </div>
  </div>
</template>

<script>
import api from '@/api/index';
import bus from '@/components/common/bus';
export default {
  props: ['setExhibition'],
  name: "exhibitionTmp",
  data () {
    return {
      exhibitionList: [],
      exhibitionId: '',
      checked1:window.sessionStorage.getItem('exhibitionID')?true:false
    }
  },
  created () {
    this.getUserExhib();
  },
  methods: {
    //锁定当前展会
    changeExhibition(e){
      if(e){
        window.sessionStorage.setItem('exhibitionID',this.exhibitionId)
      }else{
        window.sessionStorage.removeItem('exhibitionID')
      }
    },
    //获取获取当前管理员展会列表
    getUserExhib () {
      this.$http.post(api.GET_USER_EX_HIB, {})
        .then((res) => {
          console.log('展会列表1111111111', res)
          if (res.code == 1) {
            if (res.data && res.data.length > 0) {
              let eid=window.sessionStorage.getItem('exhibitionID'),flag=false;
              if(eid){
                for(let i=0;i<res.data.length;i++){
                  if(res.data[i].id == eid){
                    flag=true;
                  }
                }
              }
              this.exhibitionList = res.data;
              this.exhibitionId = flag?Number(eid):res.data[0].id;
              bus.$emit('chageMaxNumber', this.exhibitionId);
              this.setExhibition(this.exhibitionId)
            }
          }else{
            if(res.msg==='not_gl'){
              this.getUserExhib1()
            }
          }
        })
    },
    getUserExhib1 () {
      this.$http.post(api.GET_USEREXHIB_CZY, {uid:JSON.parse(localStorage.getItem('userInfo')).id})
              .then((res) => {
                console.log('展会列表22222222222', res)
                if (res.code == 1) {
                  if (res.data && res.data.length > 0) {
                    this.exhibitionList = res.data;
                    this.exhibitionId = res.data[0].id;
                    bus.$emit('chageMaxNumber', this.exhibitionId);
                    this.setExhibition(res.data[0].id)
                  }
                }else{

                }
              })
    },
    exhibitionSelect (e) {
      let id=window.sessionStorage.getItem('exhibitionID');
      console.log(id);
      if(id){
        window.sessionStorage.setItem('exhibitionID',e)
      }
      bus.$emit('chageMaxNumber', e);
      this.setExhibition(e)
    }
  }
}
</script>

<style scoped>
.handle-box {
    padding: 0 10px 0 0;
    margin-bottom: 20px;
}
</style>